I think there are some simple codes that even very young children can appreciate. The most obvious is of course the Caesar cipher.

There are many activities on the web around the Caesar cipher but many of them involve students cracking the code themselves, using frequency analysis, and so on. This could be a bit advanced for early primary, so why not introduce the basic idea of encoding in early primary and do some of that fun stuff later on...

Here are some resources that could be useful for teaching about the Caesar cipher: